package io.renren.modules.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.business.dao.BusProjectTutorDao;
import io.renren.modules.business.entity.BusProjectTutorEntity;
import io.renren.modules.business.service.BusProjectTutorService;
import io.renren.modules.business.util.PageLastUtil;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import io.renren.common.utils.PageUtils;
@Service("busProjectTutorService")
public class BusProjectTutorServiceImpl extends ServiceImpl<BusProjectTutorDao, BusProjectTutorEntity> implements BusProjectTutorService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String userName = (String) params.get("userName");
        List<Map<String, Object>> list ;
        if ( !"".equals(userName) && userName.length() != 0 ) {
            //根据用户名查询导师信息
            list = baseMapper.seleTutor(userName);
        }else {
            //查询列表
            list = baseMapper.seleTutorList();
        }
        return PageLastUtil.getPageUtils(params, list);
    }

    /**
     * 查询未被添加为项目导师的教师信息
     * @param params 页面参数
     * @return 页面内容
     */
    @Override
    public PageUtils queryTeacher(Map<String, Object> params) {
        List<UserEntity> list ;
        String username = (String) params.get("username");
        if (!"".equals(username) && username.length() !=0) {
            //根据用户名查询未被添加为导师的教师信息
            list = baseMapper.seleTeacher(username);
        }else {
            list = baseMapper.seleTeacherList();
        }
        int pageSize = 10;
        int currPage = Integer.parseInt((String) params.get("page"));
        int totalCount = list.size();
        int start = pageSize*(currPage-1);
        int end = (start + 10) > totalCount?totalCount:start + 10;
        List<UserEntity> page = list.subList(start, end);
        return new PageUtils(page, totalCount, pageSize, currPage);
    }

    @Override
    public List<Map<String, Object>> selectTutor() {
        return baseMapper.seleTutorList();
    }
}